package com.kaka.bus.engine.home.info.more;

import android.content.Intent;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaka.bus.AppCenter;
import com.kaka.bus.BuildConfig;
import com.kaka.bus.R;
import com.kaka.bus.base.BaseActivity;
import com.kaka.bus.bean.AppInfo;
import com.kaka.bus.engine.home.info.changepwd.ChangeActivity;
import com.kaka.bus.engine.home.info.opinion.OpinionActivity;
import com.kaka.bus.engine.home.info.question.QuestionActivity;
import com.kaka.bus.engine.user.login.LoginActivity;
import com.kaka.bus.listener.Listener;
import com.kaka.bus.util.U;
import com.kaka.bus.view.InfoItemView;

import butterknife.BindView;

/**
 * Created by zhangqi on 2017/4/18.
 */

public class MoreActivity extends BaseActivity<MorePresenter> implements MoreContract.View {


    @BindView(R.id.toolbar_back)
    ImageView mToolbarBack;
    @BindView(R.id.toolbar_name)
    TextView mToolbarName;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.view_info_mima)
    InfoItemView mViewInfoMima;
    @BindView(R.id.view_info_question)
    InfoItemView mViewInfoQuestion;
    @BindView(R.id.view_info_opinion)
    InfoItemView mViewInfoOpinion;
    @BindView(R.id.versionname)
    TextView mVersionname;
    @BindView(R.id.version_address)
    TextView mVersionAddress;
    @BindView(R.id.btn_self_exit)
    AppCompatButton mBtnSelfExit;

    @Override
    protected void initView() {
        super.initView();
        mToolbarBack.setOnClickListener(v -> finish());
        mToolbarName.setText("更多帮助");

        AppInfo appInfo = U.getAppInfo(this);
        mVersionname.setText(U.connectString("当前版本:",appInfo.getVersionName()));

        /**
         * 显示版本地址
         */
        if(BuildConfig.DEBUG){
            mVersionAddress.setVisibility(View.GONE);
            mVersionAddress.setText(BuildConfig.API_HOST);
        }
    }

    @Override
    protected void initListener() {
        mViewInfoOpinion.setOnClickListener(v -> startActivity(new Intent(this, OpinionActivity.class)));
        mViewInfoQuestion.setOnClickListener(v -> startActivity(new Intent(this, QuestionActivity.class)));
        mViewInfoMima.setOnClickListener(v -> startActivity(new Intent(this, ChangeActivity.class)));

        mBtnSelfExit.setOnClickListener(v -> {
            U.getSlectDialog(this, "温馨提示", "您确定要退出登录吗?", "取消", "退出",
                    new Listener.OnNormalAlertDialogChooseClickListener() {
                        @Override
                        public void onLeft() {

                        }

                        @Override
                        public void onRight() {
//                            mPresenter.unregisterPush(getUserId());
                            setUserInfo(null);
                            Intent intent = new Intent(MoreActivity.this, LoginActivity.class);
                            startActivity(intent);
                            AppCenter.cloaseApp();
                        }
                    }).show();
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_more;
    }

    @Override
    protected boolean needFullScreen() {
        return true;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

}
